<?
function SitemapSectionTheme($data){
    $str = "";
    foreach($data as $section){
        $path = parse_url($_SERVER['REQUEST_URI']);
        $uri = $path['path'];
        $str .= "<li>";        
        $link = !empty($section['fields']['link']['value']) ? $section['fields']['link']['value'] : "#";
        $name = !empty($section['fields']['name']['value']) ? $section['fields']['name']['value'] : "Undefined";
        if($uri == $link && $name){
            $GLOBALS['MAIN']->SetTitle($name);
        }
        
        $str .= "<a class='".($uri == $link ? "selected" : false)."' id='".$section['code'].":".$section['id']."' href='$link'>".$name."</a>";
        if(!empty($section['children'])){
            
            $str .= SitemapSectionTheme($section['children']);
        }
        $str .= "</li>";
    }
    return "<ul>".$str."</ul>";
}
?>
<div class="footer">
    <?= SitemapSectionTheme($result); ?>
</div>